﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using RobotGame.ScreenManagers;
using RobotGameData;

namespace RobotGame
{
    public class MiniMap
    {
        #region Properties
        private Point rootPosition = Point.Zero;
        private Texture2D textureBg;
        private Texture2D textureDisplayPoint;
        private Texture2D textureViewport;

        public Texture2D TextureViewport
        {
            get { return textureViewport; }
            set { textureViewport = value; }
        }
        public Texture2D TextureDisplayPoint
        {
            get { return textureDisplayPoint; }
            set { textureDisplayPoint = value; }
        }
        public Texture2D TextureBg
        {
            get { return textureBg; }
            set { textureBg = value; }
        }
        public Point RootPosition
        {
            get { return rootPosition; }
            set { rootPosition = value; }
        }
        private ScreenManager screenManager;
        private FightingRobot player;
        #endregion

        #region Basic Method

        public MiniMap(ScreenManager screenManager, FightingRobot player, Point position)
        {
            this.screenManager = screenManager;
            this.player = player;
            this.rootPosition = position;
        }

        public void LoadContent()
        {
            ContentManager content = screenManager.Game.Content;
            this.textureBg = content.Load<Texture2D>(@"Textures\Maps\background");
            this.textureDisplayPoint = content.Load<Texture2D>(@"Textures\Maps\Point");
            this.textureViewport = content.Load<Texture2D>(@"Textures\Maps\Rectangle");
        }
        

        public void Update(GameTime gameTime)
        {
        }

        public void Draw(GameTime gameTime, MapEngine mapEngine)
        {
            SpriteBatch spriteBatch = screenManager.SpriteBatch;
            spriteBatch.Begin();
            spriteBatch.Draw(this.textureBg, new Rectangle(this.rootPosition.X, this.rootPosition.Y, this.textureBg.Width, this.textureBg.Height), Color.White);
            float percentX = this.textureBg.Width * 1.0f / (mapEngine.Map.TileSize.X * mapEngine.Map.MapDimensions.X * 1.0f);
            float percentY = this.textureBg.Height * 1.0f / (mapEngine.Map.TileSize.Y * mapEngine.Map.MapDimensions.Y * 1.0f);

            Vector2 position = new Vector2(player.Position.X * percentX + this.rootPosition.X, player.Position.Y * percentY + this.rootPosition.Y);
            spriteBatch.Draw(this.textureDisplayPoint, new Rectangle((int)position.X, (int)position.Y, 5, 5), Color.Red);

            //spriteBatch.Draw(this.textureViewport, new Rectangle((int)(player.Position.X * percentX) + this.rootPosition.X, (int)(player.Position.Y * percentY) + this.rootPosition.Y, (int)(1024 * percentX), (int)(768 * percentY)), Color.White);
            
            spriteBatch.End();
        }
        #endregion
    }
}
